package com.yes_iot.dao;

import com.yes_iot.entity.VisualDisplay;
import com.yes_iot.entity.VisualMoudle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface VisualMoudleDao extends JpaRepository<VisualMoudle, UUID> {
    @Query("select vm from VisualMoudle vm left join VisualMoudleLibrary vml on vm.visualMoudleLibraryId=vml.id where vml.visualDisplayParentId=:parentId ")
    List<VisualMoudle> findVisualMoudelByParentId(@Param("parentId") UUID parentId);

    @Modifying
    @Query("delete from VisualMoudle where visualMoudleLibraryId=:id")
    void deleteByVisualMoudleLibraryId(@Param("id")UUID id);

    @Query("select vm from VisualMoudle vm where vm.visualMoudleLibraryId=:id")
    List<VisualMoudle> findByVisualMoudleLibraryId(@Param("id")UUID id);
}
